<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
    <title>公司级投入人月汇总</title>
	<%@ include file="/common/header/meta.jsp"%>
	<%@ include file="/common/header/script.jsp"%>
    <script type="text/javascript">
    var report_year, cal_detail_datagrid ;
	$(function() {
		var sy = $.date.format("2009", "yyyy");
		var currentYear = $.date.format(new Date(), "yyyy");
		var ey = parseInt(currentYear)+5 ;
		var yearArray = [] ;
		for(var i=sy; i<=ey; i++) {
			yearArray.push({label: i, value: i}) ;
		}
		var cy = (currentYear > ey? ey : currentYear) ;
		report_year = $("#report_year").combobox({
			valueField: 'label', textField: 'value', value: cy, data: yearArray,
			panelHeight:'auto', editable:false, autoShowPanel: true
		}) ;
		
		org_tree = $("#org_tree").tree({
			url : $.webapp.root+"/admin/system/org/combo_sync_tree.do?pid=${USER_SESSION.user.org_id}",
			lines: true, checkbox: true, cascadeCheck: true, onlyLeafCheck: true,
			onClick: function(node){
				org_tree.tree("check", node.target);
			}
	    });
		
		cal_detail_datagrid = $("#cal_detail_datagrid").datagrid({
			showFooter: true,
			idField: 'id', fit: true, border: false, pageSize: 100, pageList: [30,40,50,100,200,500,1000], rownumbers: true,
			remoteSort: true, striped:true, pagination: true, singleSelect: false,
			toolbar: '#dev_cal_bar', queryParams: {"year": cy, "startYear": sy, "endYear": ey},
			frozenColumns: [[
 			    { field: 'id', title: 'ID', width: 80, hidden: true },
 			]],
			columns: [
				[
					{ field: 'month', title: '月份', width: 100, align: 'center', sortable: false },
					{ field: 'first', title: '预定最大投入人月数', width: 120, align: 'center', sortable: false },
					{ field: 'ryTotal', title: '实际每月投入人月数', width: 120, align: 'center', sortable: false },
					{ field: 'result', title: '剩余人月数', width: 120, align: 'center', sortable: false }
		       ]
			],
			onLoadSuccess: function(node, data) {
				$.fn.datagrid.extensions.onLoadSuccess.apply(this, arguments);
				cal_detail_datagrid.datagrid('unselectAll');cal_detail_datagrid.datagrid('clearSelections');
				
			}
		});
		
	});
	
	function generator_report() {
		var dept_ids = [] ;
		var dept = org_tree.tree("getChecked") ;
		if(dept.length > 0) {
			$.each(dept, function(i,p){
				dept_ids.push(p.id) ;
			});
			loadData(dept_ids) ;
		} else {
			alertify.warning("请选择一条记录！");
		}
	}
	
	function loadData(dept_ids) {
		var year = report_year.combobox("getValue") ;
		var params = {"year": year, "deptIds": dept_ids} ;
		
		$.easyui.loading({ msg: "查询中，请稍等..." });
		$.ajax({ 
            type:"POST", 
            url:$.webapp.root + "/admin/oa/company_trry_report_action/datagrid.do", 
            dataType:"json",      
            contentType:"application/json",               
            data:JSON.stringify(params), 
            success:function(result){ 
            	if (result.rows.length > 0) {
    				$.easyui.loaded();
    				cal_detail_datagrid.datagrid("loadData", result);
    			} else {
    				alertify.warning("查询不到数据，可能部门没有项目。");
    				$.easyui.loaded();
    			}                
            },
            error: function() {
            	$.easyui.loaded();
            }
        }); 
	}
	
	
	
    </script>
</head>

<body>

	<div class="easyui-layout" data-options="fit:true">
		
		<div data-options="region:'west',split:true" style="width:250px;border-top:none;">
			<div class="easyui-layout" data-options="fit:true"> 
				<div data-options="region:'center',border:false,iconCls:'icon-hamburg-category'" title="机构/部门">
					<div id="org_tree"></div>
				</div>
			</div>
		</div>
		
		<div data-options="region:'center',border:false">
			<div class="easyui-layout" data-options="fit:true">
			
				<div data-options="region: 'north', split: false, border: true" style="border-top:none;height: 33px;">
	                <div class="easyui-toolbar">
	                	<div class="st">年份：</div>
	                	<div class="si1">
							<input id="report_year" style="width:100px;height:25px;" class="easyui-validatebox" type="text" />
						</div>
	                    <a onClick="generator_report()" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_save'">查询</a>
	                </div>
	            </div>
				
				<div data-options="region:'center'">
					<div id="cal_detail_datagrid"></div>
				</div>
				
			</div>
		</div>
		
	</div>
    
</body>
</html>



